import 'package:dodoclub/pages/comm/comm_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class AddItemPage extends StatelessWidget {
  final CommController controller = Get.find();
  final TextEditingController titleController = TextEditingController();
  final TextEditingController valueController = TextEditingController();
  late ThemeData theme;

  // 获取当前日期
  DateTime now = DateTime.now();
  @override
  Widget build(BuildContext context) {
    theme = Theme.of(context);

    return Scaffold(
      appBar: AppBar(
        scrolledUnderElevation: 0.0,
        title: Text(
          'Add a good mood',
        ),
        actions: <Widget>[
          IconButton(
            icon: const Icon(
              Icons.save_as_sharp,
              size: 22,
              // color: Colors.grey,
            ),
            onPressed: () {
              // Get.snackbar("Rompt", "Save successful",
              //     snackPosition: SnackPosition.BOTTOM);
              if (titleController.text.isNotEmpty &&
                  valueController.text.isNotEmpty) {
                controller.addItem({
                  'title': titleController.text,
                  'value': valueController.text,
                  'date': '${now.year}/${now.month}/${now.day}'
                });
                Get.back();
              }
            },
          )
        ],
      ),
      body: Padding(
        padding: EdgeInsets.all(0.0),
        child: Container(
          margin: EdgeInsets.fromLTRB(12, 12, 12, 12),
          alignment: Alignment.center,
          child: Column(
            children: [
              Container(
                padding: EdgeInsets.fromLTRB(6, 6, 6, 6),
                decoration: BoxDecoration(
                  color: const Color(0xffffffff),
                  // borderRadius: BorderRadius.circular(10),
                  borderRadius: const BorderRadius.only(
                    topLeft: Radius.circular(10.0),
                    topRight: Radius.circular(10.0),
                    bottomLeft: Radius.circular(10),
                    bottomRight: Radius.circular(10),
                  ),
                  border:
                      Border.all(color: const Color(0xff7de93b), width: 2.0),
                ),
                child: TextField(
                  controller: titleController,
                  autofocus: false,
                  style: const TextStyle(textBaseline: TextBaseline.alphabetic),
                  minLines: 1,
                  maxLines: 1,
                  // decoration: InputDecoration(
                  //   border: InputBorder.none,
                  //   hintText: 'Title....',
                  //   // contentPadding:EdgeInsets.fromLTRB(0, 0, 0, 1), // 调整边距
                  //   hintStyle: TextStyle(
                  //     color: Color.fromARGB(255, 196, 196, 196),
                  //     fontWeight: FontWeight.normal,
                  //     // height: Platform.isWindows ? null : 1.8,
                  //   ),
                  // ),
                  decoration: InputDecoration(
                    labelText: 'Title',
                    contentPadding: EdgeInsets.symmetric(
                      vertical: 14.0, // 设置垂直内边距
                      horizontal: 10.0, // 设置水平内边距
                    ),
                    labelStyle: TextStyle(
                      color:
                          theme.colorScheme.onSurfaceVariant, // 设置labelText颜色
                    ),
                    enabledBorder: OutlineInputBorder(
                      borderRadius: BorderRadius.circular(10.0),
                      borderSide: BorderSide(
                        color: const Color(0xff7de93b), // 未聚焦时的边框颜色
                        width: 0.5,
                      ),
                    ),
                    focusedBorder: OutlineInputBorder(
                      borderRadius: BorderRadius.circular(10.0),
                      borderSide: BorderSide(
                        color: theme.colorScheme.primary, // 聚焦时的边框颜色
                        width: 0.5,
                      ),
                    ),
                  ),
                ),
              ),
              SizedBox(height: 12),
              Container(
                padding: EdgeInsets.fromLTRB(6, 6, 6, 6),
                decoration: BoxDecoration(
                  color: const Color(0xffffffff),
                  // borderRadius: BorderRadius.circular(10),
                  borderRadius: const BorderRadius.only(
                    topLeft: Radius.circular(10.0),
                    topRight: Radius.circular(10.0),
                    bottomLeft: Radius.circular(10),
                    bottomRight: Radius.circular(10),
                  ),
                  border:
                      Border.all(color: const Color(0xff7de93b), width: 2.0),
                ),
                child: TextField(
                  controller: valueController,
                  autofocus: false,
                  style: const TextStyle(textBaseline: TextBaseline.alphabetic),
                  minLines: 1,
                  maxLines: 10,
                  // decoration: InputDecoration(
                  //   border: InputBorder.none,
                  //   hintText: 'Mood.....',
                  //   // contentPadding:EdgeInsets.fromLTRB(0, 0, 0, 1), // 调整边距
                  //   hintStyle: TextStyle(
                  //     color: Color.fromARGB(255, 196, 196, 196),
                  //     fontWeight: FontWeight.normal,
                  //     // height: Platform.isWindows ? null : 1.8,
                  //   ),
                  // ),
                  decoration: InputDecoration(
                    labelText: 'Mood',
                    contentPadding: EdgeInsets.symmetric(
                      vertical: 14.0, // 设置垂直内边距
                      horizontal: 10.0, // 设置水平内边距
                    ),
                    labelStyle: TextStyle(
                      color:
                          theme.colorScheme.onSurfaceVariant, // 设置labelText颜色
                    ),
                    enabledBorder: OutlineInputBorder(
                      borderRadius: BorderRadius.circular(10.0),
                      borderSide: BorderSide(
                        color: const Color(0xff7de93b), // 未聚焦时的边框颜色
                        width: 0.5,
                      ),
                    ),
                    focusedBorder: OutlineInputBorder(
                      borderRadius: BorderRadius.circular(10.0),
                      borderSide: BorderSide(
                        color: theme.colorScheme.primary, // 聚焦时的边框颜色
                        width: 0.5,
                      ),
                    ),
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}

class AddPage extends StatefulWidget {
  const AddPage({Key? key}) : super(key: key);

  @override
  _AddPageState createState() => _AddPageState();
}

class _AddPageState extends State<AddPage> {
  late ThemeData theme;

  final CommController controller = Get.find();
  final TextEditingController titleController = TextEditingController();
  final TextEditingController valueController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    theme = Theme.of(context);
    return Scaffold(
        backgroundColor: theme.scaffoldBackgroundColor,
        // appBar: AppBar(centerTitle: true, title: const Text("Home")),
        appBar: AppBar(
          scrolledUnderElevation: 0.0,
          title: Text(
            'Add a good mood',
          ),
          actions: <Widget>[
            IconButton(
              icon: const Icon(
                Icons.save_as_sharp,
                size: 22,
                // color: Colors.grey,
              ),
              onPressed: () {
                Get.snackbar("Rompt", "Save successful",
                    snackPosition: SnackPosition.BOTTOM);
                if (titleController.text.isNotEmpty &&
                    valueController.text.isNotEmpty) {
                  controller.addItem({
                    'title': titleController.text,
                    'value': valueController.text,
                  });
                  Get.back();
                }
              },
            )
          ],
        ),
        body: SafeArea(
          child: Container(
            margin: EdgeInsets.fromLTRB(12, 12, 12, 12),
            alignment: Alignment.center,
            child: Column(
              children: [
                Container(
                  padding: EdgeInsets.fromLTRB(6, 6, 6, 6),
                  decoration: BoxDecoration(
                    color: const Color(0xffffffff),
                    // borderRadius: BorderRadius.circular(10),
                    borderRadius: const BorderRadius.only(
                      topLeft: Radius.circular(10.0),
                      topRight: Radius.circular(10.0),
                      bottomLeft: Radius.circular(10),
                      bottomRight: Radius.circular(10),
                    ),
                    border:
                        Border.all(color: const Color(0xff7de93b), width: 2.0),
                  ),
                  child: TextField(
                    controller: titleController,
                    autofocus: false,
                    style:
                        const TextStyle(textBaseline: TextBaseline.alphabetic),
                    minLines: 1,
                    maxLines: 1,
                    // decoration: InputDecoration(
                    //   border: InputBorder.none,
                    //   hintText: 'Title....',
                    //   // contentPadding:EdgeInsets.fromLTRB(0, 0, 0, 1), // 调整边距
                    //   hintStyle: TextStyle(
                    //     color: Color.fromARGB(255, 196, 196, 196),
                    //     fontWeight: FontWeight.normal,
                    //     // height: Platform.isWindows ? null : 1.8,
                    //   ),
                    // ),
                    decoration: InputDecoration(
                      labelText: 'Title',
                      contentPadding: EdgeInsets.symmetric(
                        vertical: 14.0, // 设置垂直内边距
                        horizontal: 10.0, // 设置水平内边距
                      ),
                      labelStyle: TextStyle(
                        color:
                            theme.colorScheme.onSurfaceVariant, // 设置labelText颜色
                      ),
                      enabledBorder: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(10.0),
                        borderSide: BorderSide(
                          color: const Color(0xff7de93b), // 未聚焦时的边框颜色
                          width: 0.5,
                        ),
                      ),
                      focusedBorder: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(10.0),
                        borderSide: BorderSide(
                          color: theme.colorScheme.primary, // 聚焦时的边框颜色
                          width: 0.5,
                        ),
                      ),
                    ),
                  ),
                ),
                SizedBox(height: 12),
                Container(
                  padding: EdgeInsets.fromLTRB(6, 6, 6, 6),
                  decoration: BoxDecoration(
                    color: const Color(0xffffffff),
                    // borderRadius: BorderRadius.circular(10),
                    borderRadius: const BorderRadius.only(
                      topLeft: Radius.circular(10.0),
                      topRight: Radius.circular(10.0),
                      bottomLeft: Radius.circular(10),
                      bottomRight: Radius.circular(10),
                    ),
                    border:
                        Border.all(color: const Color(0xff7de93b), width: 2.0),
                  ),
                  child: TextField(
                    controller: valueController,
                    autofocus: false,
                    style:
                        const TextStyle(textBaseline: TextBaseline.alphabetic),
                    minLines: 1,
                    maxLines: 10,
                    // decoration: InputDecoration(
                    //   border: InputBorder.none,
                    //   hintText: 'Mood.....',
                    //   // contentPadding:EdgeInsets.fromLTRB(0, 0, 0, 1), // 调整边距
                    //   hintStyle: TextStyle(
                    //     color: Color.fromARGB(255, 196, 196, 196),
                    //     fontWeight: FontWeight.normal,
                    //     // height: Platform.isWindows ? null : 1.8,
                    //   ),
                    // ),
                    decoration: InputDecoration(
                      labelText: 'Mood',
                      contentPadding: EdgeInsets.symmetric(
                        vertical: 14.0, // 设置垂直内边距
                        horizontal: 10.0, // 设置水平内边距
                      ),
                      labelStyle: TextStyle(
                        color:
                            theme.colorScheme.onSurfaceVariant, // 设置labelText颜色
                      ),
                      enabledBorder: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(10.0),
                        borderSide: BorderSide(
                          color: const Color(0xff7de93b), // 未聚焦时的边框颜色
                          width: 0.5,
                        ),
                      ),
                      focusedBorder: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(10.0),
                        borderSide: BorderSide(
                          color: theme.colorScheme.primary, // 聚焦时的边框颜色
                          width: 0.5,
                        ),
                      ),
                    ),
                  ),
                )
              ],
            ),
          ),
        ));
  }
}
